<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/16
  Time: 22:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

</head>
<body>
<script src="jquery-1.10.1.min.js"></script>
<input type="file" name="file" id="file"/>
<input type="button" value="上传" onclick="upload()"/>
<div><img id="imgBox" src="" style="width: auto; height: auto; max-width: 300px; max-height: 300px; }" /></div>
<script type="text/javascript">
    function upload(){
        var formdata=new FormData( );
        if(!$("#file").val()){
            return;
        }
        formdata.append("key1","efg");
        formdata.append("file" , $("#file")[0].files[0]);//获取文件法
        $.ajax({
            url: '/upload.html',
            type: 'POST',
            data: formdata,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (json) {
                $("#imgBox").attr("src", json);
            }
        });
    }
</script>
</body>
</html>
